package multiformat;

import java.lang.Math;

public class SymbolicExpressions {
	
	
	public SymbolicExpressions() {
		
	}
	
	private double pi() {
		return 3.14; 
	}
	
	private double goldenRatio() {
		return 1.61;
	}
	
	private double sin(double x) {
		return Math.asin(x);
	}
	
	private double cos(double x) {
		return Math.acos(x);
	}
	
	public double parseExpression(String expression) {
		int numberStart = expression.indexOf('(')+1;
		int numberEnd = expression.indexOf(')');
		double number = 0.0;
		String e = "niets";		
		
		if (expression.length() > numberEnd+1)
			return number;
		
		if (numberEnd > numberStart) {			
			number = Double.parseDouble(expression.substring(numberStart,numberEnd));
		} 
			
		e = expression.substring(1,numberStart-1); 
		
		if (e.equals("PI")) 
			return pi();		
		if (e.equals("GR")) 
			return goldenRatio();
		if (e.equals("SIN"))
			return sin(number);
		if (e.equals("COS"))
			return cos(number);
		
		
		return number;
	}

}
